home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
-
- File: ISpSampleUSB.h
-
- Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
-
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- *************************************************************************************/
-
-
- #ifndef __ISPSAMPLEUSB__
- #define __ISPSAMPLEUSB__
-
- #ifndef __MACTYPES__
- #include <MacTypes.h>
- #endif
-
- #ifndef __DESKBUS__
- #include <DeskBus.h>
- #endif
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- #ifndef __INPUTSPROCKET__
- #include <InputSprocket.h>
- #endif
-
- #include "UniversalHIDModule.h"
-
- #include "ISpPlugInUI.h"
- #include "ISpSampleUSBRes.h"
- #include "ListUtils.h"
-
- // these constants are used to describe specific values for an element (a usbElementKey)
- enum
- {
- // it is important that all buttons come first and start at 1
- kUSB_button1_element = 1,
- kUSB_button2_element,
- kUSB_button3_element,
- kUSB_button4_element,
- kUSB_button5_element,
- kUSB_button6_element,
- kUSB_button7_element,
- kUSB_button8_element,
- kUSB_trigger_element,
- kUSB_buttonStart_element,
- kUSB_buttonSelect_element,
- kUSB_povhat_element,
- kUSB_povhat4_element,
- kUSB_dpad_element,
- kUSB_dpad4_element,
- kUSB_xaxis_element,
- kUSB_yaxis_element,
- kUSB_throttle_element,
- kUSB_rudder_element,
- kUSB_trim_element,
- kUSB_gas_element,
- kUSB_brake_element,
- kUSB_axis_element
- };
-
- class ISpUSBDevice : public ISpPlugInUI
- {
- public:
- ISpUSBDevice(const UHIDModuleDispatchTablePtr hidmoduleDispatchTable,
- const USBDeviceRef usbDeviceRef, const FSSpec &inFileSpec);
- virtual ~ISpUSBDevice();
-
- void FinishConstruction(void);
-
- public:
- // these must be overridden in the subclass
- OSStatus Init( UInt32 count,
- ISpNeed needs[],
- ISpElementReference virtualElements[],
- Boolean used[],
- OSType appCreatorCode,
- OSType subCreatorCode,
- UInt32 reserved,
- void* reserved2);
- OSStatus Stop(void);
- OSStatus HandleEvent(EventRecord &theEvent, Boolean &handled);
- OSStatus Show(DialogPtr theDialog, short dialogItemNumber, Rect &r);
- OSStatus Hide(void);
- OSStatus BeginConfiguration(UInt32 count, ISpNeed needs[]);
- OSStatus EndConfiguration(Boolean accept);
- OSStatus GetIcon(short &iconSuiteResourceId);
- OSStatus GetState(UInt32 buflen, void *buffer, UInt32 &length);
- OSStatus SetState(UInt32 length, void *buffer);
- OSStatus SetActive(Boolean active);
- OSStatus DialogItemHit(short itemHit);
-
- OSStatus Tickle(void);
- OSStatus InterruptTickle(void);
- OSStatus Draw(void);
- OSStatus Click(const EventRecord &event);
- OSStatus ADBReInit(Boolean inPostProcess);
-
- public:
- static OSStatus Initialize(FSSpec fileSpec);
- static void Terminate(void);
-
- void AutoConfigure(Boolean used[]);
-
- Boolean TryButtonConfig (UInt32 inNeedIndex, Boolean inOnlyExactMatch);
- Boolean TryAxisConfig (UInt32 inNeedIndex, Boolean inOnlyExactMatch);
- Boolean TryDPadConfig (UInt32 inNeedIndex, Boolean inOnlyExactMatch);
- Boolean TryStickConfig (UInt32 inNeedIndex, Boolean inOnlyExactMatch);
-
- Boolean TryStickXAxisConfig (UInt32 inNeedIndex);
- Boolean TryStickYAxisConfig (UInt32 inNeedIndex);
- Boolean TryDPadXAxisConfig (UInt32 inNeedIndex);
- Boolean TryDPadYAxisConfig (UInt32 inNeedIndex);
- Boolean TryTrimConfig (UInt32 inNeedIndex);
- Boolean TryThrottleConfig (UInt32 inNeedIndex);
- Boolean TryRudderConfig (UInt32 inNeedIndex);
- Boolean TryGasConfig (UInt32 inNeedIndex);
- Boolean TryBrakeConfig (UInt32 inNeedIndex);
-
- private:
- static void UIDNotifyProc(USBDeviceNotificationParameterBlockPtr passedPB);
- inline void HandleDisappearedDevice(USBDeviceNotificationParameterBlockPtr passedPB);
-
- static List * gUSBDevices;
- UHIDModuleDispatchTablePtr mHIDModuleDispatchTable;
- USBDeviceNotificationParameterBlock mConnectionNotifyPB;
- UHIDModuleConnectionID mUHIDConnectionID;
-
- USBDeviceRef mUSBDeviceRef;
-
- private:
- virtual OSStatus Patch(void);
- virtual OSStatus Unpatch(void);
-
-
- public:
- void ParseData(
- Ptr inBuffer);
-
- public:
-
- // virtual element code
- void StartVirtualElements(void);
- void StopVirtualElements(void);
-
- UInt32 * GetDialogItemToNeedMapping () { return mDialogItemToNeedMapping; };
-
- private:
- UInt32 mDialogItemToNeedMapping[kDialogItem_NumPopups+1]; // we dont use index 0
-
- private:
- // reverse
- Boolean mReverseStick;
- Boolean mReverseTrim;
- Boolean mReverseThrottle;
- Boolean mReverseRudder;
- Boolean mReverseDPad[4];
-
- private:
- short mWhichDevice;
-
- // actual elements, nil if doesn't exist
- ISpDeviceReference mDevice;
-
-
- private:
- // ui code, internal
- // internal
- Boolean mVisable;
- Boolean mActive;
- volatile Boolean mVirtualElementsValid;
-
- void SetVirtualElements(void);
- Boolean IsPressed (short inDialogItem); // is this dialog item 'pressed' (ie on the device)
-
- Boolean mPopupPressed[kDialogItem_NumPopups];
-
- void UpdateSingleButton(UInt32 curButton, UInt32 index);
- void UpdateAllButtons(void);
-
- private:
- void ClearVirtuals (void);
-
- OSStatus PushAllNonDefaultValues(void);
-
- private:
- FSSpec mFileSpec;
- Rect mRect;
- short mResRef;
-
- typedef struct
- {
- UInt32 version;
-
- UInt32 mapping[kDialogItem_NumPopups];
-
- UInt32 flags;
- } USBSetVersion1;
-
- enum
- {
- kSetReverseStick = 0x00000001,
- kSetReverseTrim = 0x00000002,
- kSetReverseThrottle = 0x00000004,
- kSetReverseRudder = 0x00000008,
- kSetReverseDPad1 = 0x00000010,
- kSetReverseDPad2 = 0x00000020,
- kSetReverseDPad3 = 0x00000040,
- kSetReverseDPad4 = 0x00000080
- };
-
- enum
- {
- kSetVersion1 = '0001'
- };
-
- enum
- {
- kMappingFlag_AxisIsSymmetric = 0x00000001
- };
-
- typedef struct
- {
- UInt32 usbElementKey; // code for what kind of thing this is
-
- ISpElementKind kind; // kind of element it is
- ISpElementReference element; // references
- UInt32 lastValue;
-
- // (axis value - min) * multiplier = input axis value
- SInt32 min;
- SInt32 max;
- double multiplier;
-
- // does this usb element map to an ISp element ?
- Boolean valid; // false -> ignore this element
- Boolean highLevelValid; // true -> use this for high level
- UInt32 highIndex; // index within element kind
-
- UInt32 flags; // currently just used for axis symmetry
- } USBMapping;
-
- UInt32 mUSBElementCount;
- USBMapping * mUSBMapping;
-
- OSStatus BuildMapping(void);
- void DisposeMapping(void);
-
- public:
- enum { kMaxHighLevelDpads = 4, kMaxHighLevelButtons = 12 };
-
- private:
- UInt32 mNumOrderedButtons;
- UInt8 mOrderedButtonsIndecies[kMaxHighLevelButtons];
-
- typedef struct
- {
- Boolean hasXAxis;
- Boolean hasYAxis;
- Boolean hasTrim;
- Boolean hasThrottle;
- Boolean hasRudder;
- Boolean hasBrake;
- Boolean hasGas;
-
- UInt32 numDPads;
- UInt32 numButtons;
-
- UInt32 triggerButtonIndex;
- UInt32 startButtonIndex;
- UInt32 selectButtonIndex;
-
- Boolean is4WayDPad[kMaxHighLevelDpads];
-
- // these indecis are into our mJoyManagerMapping array
- UInt32 xAxisIndex;
- UInt32 yAxisIndex;
- UInt32 trimIndex;
- UInt32 throttleIndex;
- UInt32 rudderIndex;
- UInt32 brakeIndex;
- UInt32 gasIndex;
- UInt32 buttonIndex[kMaxHighLevelButtons];
- UInt32 dpadIndex[kMaxHighLevelDpads];
-
- } HighLevelFeatures;
-
- HighLevelFeatures features;
- void GetFeatures (void);
-
- typedef struct
- {
- // axis
- UInt32 xAxis;
- UInt32 yAxis;
- UInt32 trim;
- UInt32 throttle;
- UInt32 rudder;
- UInt32 brake;
- UInt32 gas;
-
- UInt32 xAxis_as_buttons[2];
- UInt32 yAxis_as_buttons[2];
- UInt32 trim_as_buttons[2];
- UInt32 throttle_as_buttons[2];
- UInt32 rudder_as_buttons[2];
- UInt32 brake_as_button;
- UInt32 gas_as_button;
-
- // dpads
- UInt32 dpads[kMaxHighLevelDpads];
- UInt32 dpads_as_buttons[kMaxHighLevelDpads][4]; // t,l,b,r
- UInt32 dpads_as_axis[kMaxHighLevelDpads][2]; // x,y
-
- // buttons
- UInt32 buttons[kMaxHighLevelButtons];
- } HighLevelData;
-
- void SetAsFields(HighLevelData ¤t);
- void PushDataToVirtuals(HighLevelData ¤t);
-
- typedef struct
- {
- // axis
- ISpElementReference xAxis;
- ISpElementReference yAxis;
- ISpElementReference trim;
- ISpElementReference throttle;
- ISpElementReference rudder;
- ISpElementReference brake;
- ISpElementReference gas;
-
- ISpElementReference stickMovement;
- ISpElementReference stickDPad;
-
- ISpElementReference xAxis_as_buttons[2];
- ISpElementReference yAxis_as_buttons[2];
- ISpElementReference trim_as_buttons[2];
- ISpElementReference throttle_as_buttons[2];
- ISpElementReference rudder_as_buttons[2];
- ISpElementReference brake_as_button;
- ISpElementReference gas_as_button;
-
- // dpads
- ISpElementReference dpads[kMaxHighLevelDpads];
- ISpElementReference dpads_as_movement[kMaxHighLevelDpads];
- ISpElementReference dpads_as_buttons[kMaxHighLevelDpads][4]; // t,l,b,r
- ISpElementReference dpads_as_axis[kMaxHighLevelDpads][2]; // x,y
-
- // buttons
- ISpElementReference buttons[kMaxHighLevelButtons];
- } VirtualElements;
-
- VirtualElements virtuals;
- HighLevelData mOldHLData;
- HighLevelData mCurHLData;
-
- private:
- // 6/24/98 removed mOrphan, check for non-zeroness of mHIDModuleDispatchTable instead
- // Boolean mOrphan;
- Boolean mMustRestorePatch;
- Boolean mPatched;
-
- private:
- void DoReverse(short dialog_item, Boolean &the_boolean);
-
- public:
- // ••• these routines _should_ be implemented by subclass
- virtual OSStatus GetSize(Point &minimum, Point &best);
- virtual UInt16 GetDeviceResID(void);
-
- // ••• these routines must be implemented by subclass
- // static Boolean IsSubclassName(UHIDModuleDispatchTablePtr hidmoduleDispatchTable) { return false; };
- virtual UInt32 GetDeviceElementCount (void);
- virtual void GetElementName (UInt32 inElementIndex, Str31 outElementName);
- virtual UInt32 GetElementKey(UInt32 inElementIndex);
- virtual SInt32 GetElementMinValue(UInt32 inElementIndex);
- virtual SInt32 GetElementMaxValue(UInt32 inElementIndex);
-
- virtual SInt32 ParseElementValue(UInt32 inElementIndex, Ptr inBuffer);
-
- // ••• end subclass routines
-
- };
-
- class TMTopGun : public ISpUSBDevice
- {
- public:
- TMTopGun(const UHIDModuleDispatchTablePtr hidmoduleDispatchTable,
- const USBDeviceRef usbDeviceRef, const FSSpec &inFileSpec);
- virtual ~TMTopGun();
-
- static Boolean IsTMTopGun(UHIDModuleDispatchTablePtr hidmoduleDispatchTable);
-
- virtual OSStatus GetSize(Point &minimum, Point &best);
- virtual UInt16 GetDeviceResID(void);
-
- virtual UInt32 GetDeviceElementCount(void);
- virtual UInt32 GetElementKey(UInt32 inElementIndex);
- virtual void GetElementName (UInt32 inElementIndex, Str31 outElementName);
- virtual SInt32 GetElementMinValue(UInt32 inElementIndex);
- virtual SInt32 GetElementMaxValue(UInt32 inElementIndex);
-
- virtual SInt32 ParseElementValue(UInt32 inElementIndex, Ptr inBuffer);
-
- enum
- {
- kTMTopGun_XAxis, // 8 bits (-128 to 127)
- kTMTopGun_YAxis, // 8 bits (-128 to 127)
-
- kTMTopGun_Hat, // 4 bits (0 is idle, 1 is up going clockwise)
- kTMTopGun_Trigger, // 1 bit
- kTMTopGun_ThumbHigh, // 1 bit
- kTMTopGun_ThumbLow, // 1 bit
- kTMTopGun_Pinky, // 1 bit
-
- kTMTopGun_NumElements
- };
-
-
- };
-
- class GravisPad : public ISpUSBDevice
- {
- public:
- GravisPad(const UHIDModuleDispatchTablePtr hidmoduleDispatchTable,
- const USBDeviceRef usbDeviceRef, const FSSpec &inFileSpec);
- virtual ~GravisPad();
-
- static Boolean IsGravisPad(UHIDModuleDispatchTablePtr hidmoduleDispatchTable);
-
- virtual OSStatus GetSize(Point &minimum, Point &best);
- virtual UInt16 GetDeviceResID(void);
-
- virtual UInt32 GetDeviceElementCount(void);
- virtual UInt32 GetElementKey(UInt32 inElementIndex);
- virtual void GetElementName (UInt32 inElementIndex, Str31 outElementName);
- virtual SInt32 GetElementMinValue(UInt32 inElementIndex);
- virtual SInt32 GetElementMaxValue(UInt32 inElementIndex);
-
- virtual SInt32 ParseElementValue(UInt32 inElementIndex, Ptr inBuffer);
-
- enum
- {
- kGravisPad_DPad, // 16 bits, 8 bit x then 8 bit y
-
- kGravisPad_Red, // 1 bit
- kGravisPad_Yellow, // 1 bit
- kGravisPad_Green, // 1 bit
- kGravisPad_Blue, // 1 bit
-
- kGravisPad_LeftBottom, // 1 bit
- kGravisPad_RightBottom, // 1 bit
- kGravisPad_LeftTop, // 1 bit
- kGravisPad_RightTop, // 1 bit
-
- kGravisPad_Select, // 1 bit
- kGravisPad_Start, // 1 bit
-
- kGravisPad_NumElements
- };
-
-
- };
-
-
- #endif // __ISPSAMPLEUSB__
-